/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: TestBigdecimal
 * Author:   Administrator
 * Date:     2021/8/22 0022 19:11
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package cn.hxlc.tie.demo.modular.jf.controller;


import java.math.BigDecimal;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Administrator
 * @create 2021/8/22 0022
 * @since 1.0.0
 */
public class TestBigdecimal {

   public static void main(String[] args)
   {
       BigDecimal a = new BigDecimal("2.4000000001");
       BigDecimal b = new BigDecimal("2.4000000002");
       BigDecimal result ;
// 加
       result = a.add(b);
       System.out.println("加法"+result);
// 减
       result = a.subtract(b);
       System.out.println("减法"+result);
// 乘
       result = a.multiply(b);
       System.out.println("乘法"+result);
// 除
       result = a.divide(b,BigDecimal.ROUND_HALF_EVEN);
       System.out.println("除法"+result);

       result = a.divide(b,BigDecimal.ROUND_UP);//向上取整
       System.out.println("除法"+result);

       result = a.divide(b,BigDecimal.ROUND_DOWN);//向下取整
       System.out.println("除法"+result);

       result = a.divide(b,BigDecimal.ROUND_CEILING);//向正无穷取整
       System.out.println("除法"+result);

       result = a.divide(b,BigDecimal.ROUND_FLOOR);//向负无穷取整
       System.out.println("除法"+result);



       if (a.compareTo(b)==1) {
           //如果为1,则说明a大于b
           System.out.println("a大于b");
       }else if(a.compareTo(b)==0) {
           //如果为0,这说明a等于b
           System.out.println("a等于b");
       }else if(a.compareTo(b)==-1) {
           //如果为-1,这说明a小于b
           System.out.println("a小于b");
       }


       //ROUND_CEILING    //向正无穷方向舍入
   }

}
